package Videojuego;

import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;


public class NavEspacial extends Objeto{

	private static String nave = "craft.png";

	private int dx;
	private int dy;
	private ArrayList<Misil> misiles;
	private final int naveTamanio = 20;

	public NavEspacial() {
		super(20, 20, nave);
		misiles = new ArrayList<Misil>();		
	}

	@Override 
	public void mover() {
		posicionX += dx;
		posicionY += dy;

		if (posicionX < 1)
			posicionX = 1;
		if (posicionY < 1)
			posicionY = 1;

	}

	public ArrayList<Misil> misiles() {
		return misiles;
	}

	public Rectangle colisiones_() {
		return new Rectangle(posicionX, posicionY, ancho, alto);
	}

	public void keyPressed(KeyEvent e) {

		int key = e.getKeyCode();

		if (key == KeyEvent.VK_SPACE) {
			Dispara();
		}

		if (key == KeyEvent.VK_LEFT) {
			dx = -1;
		}

		if (key == KeyEvent.VK_RIGHT) {
			dx = 1;
		}

		if (key == KeyEvent.VK_UP) {
			dy = -1;
		}

		if (key == KeyEvent.VK_DOWN) {
			dy = 1;
		}
	}

	public void Dispara() {
		misiles.add(new Misil(posicionX + naveTamanio, posicionY    + naveTamanio / 2));
	}

	public void keyReleased(KeyEvent e) {
		int key = e.getKeyCode();

		if (key == KeyEvent.VK_LEFT) {
			dx = 0;
		}

		if (key == KeyEvent.VK_RIGHT) {
			dx = 0;
		}

		if (key == KeyEvent.VK_UP) {
			dy = 0;
		}

		if (key == KeyEvent.VK_DOWN) {
			dy = 0;
		}
	}
}
